// { "data": [{ "id": true, "name": null }, { "id": "<a>false</a>", "name": "空222" }], "code": 1 }
var vueApp = new Vue({
    el: "#app",
    data: function () {
        return {
            jsonStr: ""
        }
    },
    watch: {
        // 监听jsonStr数据的改变
        jsonStr: function (newVal, oldVal) {
            this.jsonFormat();
        }
    },
    methods: {
        // 格式化json
        jsonFormat() {
            $('#jsonformat').jsonViewer(JSON.parse(this.jsonStr), {
                collapsed: false, withQuotes: false
            });
        },
        // 点击格式化json
        clickFormat() {
            try {
                this.jsonFormat();
            } catch (e) {
                this.showMsg("ERROR -> " + e, 'error');
            }
        },
        // 复制格式化后的json字符串
        copyJson() {
            axiosDoAjax('POST', ip + '/utils/json', this.jsonStr, function (result) {
                if (result.code === 0) {
                    writePaste(result.data);
                    vueObj.showMsg('已复制内容到粘贴板')
                }
            });
        }
    },
    created: function () {
        initShowMsg(this);
        vueObj = this;
    }
})